package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.util.Constant;

import java.util.List;
import java.util.Map;

/**
 * Created by pig33 on 15-06-19.
 */
public class ActivityListViewAdapter extends BaseAdapter {

    private List<Map<String, Object>> dataList;
    private LayoutInflater mInflater;
    private RequestQueue mQueue;
    private Context mContext;



    public ActivityListViewAdapter(Context context, RequestQueue mQueue, List<Map<String, Object>> dataList){
        mInflater= LayoutInflater.from(context);
        this.mQueue=mQueue;
        this.dataList=dataList;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        Map<String,Object> item=null;
        if(null!=dataList){
            item=dataList.get(position);
        }
        return item;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.home_item_tab1,null);
            holder=new ViewHolder();
            holder.activityTitle= (TextView) convertView.findViewById(R.id.tv_home_title);
            holder.newsImg= (ImageView) convertView.findViewById(R.id.iv_home_tab1_img);
            holder.activityDiscount = (TextView) convertView.findViewById(R.id.tv_discount);
            holder.layoutDis = (LinearLayout) convertView.findViewById(R.id.layout_dis);
            holder.ShowName = (TextView) convertView.findViewById(R.id.tv_home_showname);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        String discount =(String) dataList.get(position).get("discount");
        if (!"".equals(discount)||null!=discount){
            if ("10".equals(discount)){
                holder.layoutDis.setVisibility(View.GONE);
            }else {
                holder.activityDiscount.setText(discount);
            }
        }
        holder.activityTitle.setText((String)dataList.get(position).get("text"));
        holder.ShowName.setText((String) dataList.get(position).get("shopName"));
        String imgId= (String) dataList.get(position).get("image");
        String imgUrl= Constant.BaseWebHost + imgId;
        Glide.with(mContext).load(imgUrl).into(holder.newsImg);
        return convertView;
    }

    private static class ViewHolder {
        private ImageView newsImg;
        private TextView activityTitle;
        private TextView activityDiscount;
        private LinearLayout layoutDis;
        private TextView ShowName;
    }
}
